<template>
	<div id="app">
		<router-view />
	</div>
</template>

<script>

export default {
	name: 'App',
	comments: {
		device
	},
	data() {
		return {
			currentNotification: null,
			obj: {
				// 后台给的ws路径
				path: `ws://localhost:8088/myWs/1`,
				onMsg: (msg) => {
					// this.onit()

					console.log('数据更新了');
					// console.log(msg.data)
					const body = JSON.parse(msg.data);

					// console.log(body.device)
					// console.log(body.sn)
					// console.log(body.transtype)

					// console.log(window.document)
					let deviceName = body.device
					let title = ''
					// console.log('12312312321321')
					console.log(body)
					if (body.transtype == '1000') {
						title = '收到组网请求'
						// this.webSend(msg.data)
						// console.log('aaaaa')
						this.$store.dispatch('zuWang/setZuwangFromJS', body.ip)
						// //弹出一个框
						if (this.currentNotification) {
							this.currentNotification.close();
						}
						this.currentNotification = this.$notify({
							title: title,
							message: '设备名称：' + deviceName,
							type: 'success',
							duration: 2000
						})
					} else if (body.transtype == '1002') {

						this.$store.dispatch('zuWang/setZuwangRes', body.ip)
						if (this.currentNotification) {
							this.currentNotification.close();
						}
						this.currentNotification = this.$notify({
							title: "保存组网参数成功",
							message: '设备名称：' + deviceName,
							type: 'success',
							duration: 2000
						})

					}
					else if (body.transtype == '1004') {

						console.log(body.uniStr)
						console.log(body)
						//接收机
						if (body.device == 'YSRP') {
							if (body.command.includes('SWITCHAFC')) {
								title = '读取业务参数'
								//需要将值传入businessParam.vue  用getter？
								this.$store.dispatch('param/setBusiParamMessage', body.uniStr)
							}
							else {
								title = '保存业务参数'
								//需要将值传入businessParam.vue  用getter？
							}
						}
						else if (body.device == 'YIRC') {
							title = '读取远程控制参数'
							this.$store.dispatch('param/setRemoteParamMessage', body.uniStr)
						}


						this.$message({
							title: title,
							message: title + '成功',
							type: 'success',
							duration: 2000
						})
					}



					//vuex通信 
					//传递给组网界面
					//传递给参数界面
					//传递给系统管理界面

				}, onOpen: (msg) => {
					console.log('建立连接成功');
				}, onErr: () => {
					console.log('建立连接失败');
				}
			}
		}
	},
	created() {
		this.$cu.websocket(this.obj)
	},
	methods: {
		// async webSend(msgData) {
		// 	// console.log(data)
		// 	//将数据存入txt
		// 	const { data } = await saveConfig(msgData)
		// 	this.$store.dispatch('zuWang/setZuwangFromJS', data.ip)
		// }
	}
}
//引入设备组网组件
import device from '@/views/network/device';
import axios_c from '@/utils/requestcopy'

export function saveConfig(data) {
	console.log('--------------------------')
	console.log(data)
	return axios_c({
		url: '/zuwang/save',
		method: 'post',
		data
	})
}
</script>
